package com.uzai.console.web.groupsendjob;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.groupsendjob.GroupSendJobIdDto;
import com.uzai.console.dto.groupsendjob.GroupSendJobQuery;
import com.uzai.console.dto.groupsendjob.GroupSendJobUpdateDto;
import com.uzai.console.dto.groupsendjobdetail.*;
import com.uzai.console.enums.GroupSendJobSourceEnum;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.JdTokenMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.device.DeviceTypeService;
import com.uzai.console.service.groupsendjob.GroupSendJobDetailService;
import com.uzai.console.service.groupsendjob.GroupSendJobService;
import com.uzai.console.service.order.OrderReStatusService;
import com.uzai.console.service.order.OrderSourceService;
import com.uzai.console.service.order.OrderStatusService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.service.wechatprivate.DeviceWechatInfoService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.groupsendjob.GroupSendJobInfoVo;
import com.uzai.console.vo.groupsendjob.GroupSendJobSubVo;
import com.uzai.console.vo.groupsendjob.GroupSendMsgVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 群发任务
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "群发任务详情",tags = "客户维护|群发任务详情")
@ApiSort(28)
@RestController
public class GroupSendJobDetailController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(GroupSendJobDetailController.class);

    @Autowired
    private GroupSendJobDetailService groupSendJobDetailService;

    @ApiOperation(value = "查询群发子任务列表", notes = "查询群发子任务列表", response = GroupSendJobSubVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/groupSendJobDetail/findGroupSendJobSubList")
    public Object findGroupSendJobSubList(@RequestBody GroupSendJobSubQuery groupSendJobSubQuery){
        return groupSendJobDetailService.findGroupSendJobSubList(groupSendJobSubQuery);
    }

    @ApiOperation(value = "查询群发子任务详情", notes = "查询群发子任务详情", response = GroupSendJobSubVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/groupSendJobDetail/findGroupSendJobSub")
    public Object findGroupSendJobSub(@RequestBody GroupSendJobSubIdDto groupSendJobSubIdDto){
        return groupSendJobDetailService.findGroupSendJobSub(groupSendJobSubIdDto);
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改群发子任务", notes = "修改群发子任务")
    @ApiOperationSupport(order = 4)
    @PostMapping("/groupSendJobDetail/updateGroupSendJobSub")
    public Object updateGroupSendJobSub(@RequestBody GroupSendJobSubUpdateDto groupSendJobSubUpdateDto){
        groupSendJobDetailService.updateGroupSendJobSub(groupSendJobSubUpdateDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "开始群发子任务", notes = "开始群发子任务")
    @ApiOperationSupport(order = 5)
    @PostMapping("/groupSendJobDetail/startGroupSendJobSub")
    public Object startGroupSendJobSub(@RequestBody GroupSendJobSubIdDto groupSendJobSubIdDto){
        groupSendJobDetailService.startGroupSendJobSub(groupSendJobSubIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "暂停群发子任务", notes = "暂停群发子任务")
    @ApiOperationSupport(order = 5)
    @PostMapping("/groupSendJobDetail/pauseGroupSendJobSub")
    public Object pauseGroupSendJobSub(@RequestBody GroupSendJobSubIdDto groupSendJobSubIdDto){
        groupSendJobDetailService.pauseGroupSendJobSub(groupSendJobSubIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "结束群发子任务", notes = "结束群发子任务")
    @ApiOperationSupport(order = 6)
    @PostMapping("/groupSendJobDetail/finishGroupSendJobSub")
    public Object finishGroupSendJobSub(@RequestBody GroupSendJobSubIdDto groupSendJobSubIdDto){
        groupSendJobDetailService.finishGroupSendJobSub(groupSendJobSubIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除群发子任务", notes = "删除群发子任务")
    @ApiOperationSupport(order = 7)
    @PostMapping("/groupSendJobDetail/deleteGroupSendJobSub")
    public Object deleteGroupSendJobSub(@RequestBody GroupSendJobSubIdDto groupSendJobSubIdDto){
        groupSendJobDetailService.deleteGroupSendJobSub(groupSendJobSubIdDto);
        return true;
    }

    @ApiOperation(value = "查询群发消息列表", notes = "查询群发消息列表", response = GroupSendMsgVo.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/groupSendJobDetail/findGroupSendMsgList")
    public Object findGroupSendMsgList(@RequestBody GroupSendMsgQuery groupSendMsgQuery){
        if(groupSendMsgQuery.getOrderItemList() == null || groupSendMsgQuery.getOrderItemList().size() == 0){
            groupSendMsgQuery.setOrderByField("delay"); //默认发送间隔升序排序
        }
        return groupSendJobDetailService.findGroupSendMsgList(groupSendMsgQuery);
    }

    @ApiOperation(value = "查询群发子任务详情", notes = "查询群发子任务详情", response = GroupSendMsgVo.class)
    @ApiOperationSupport(order = 9)
    @PostMapping("/groupSendJobDetail/findGroupSendMsg")
    public Object findGroupSendMsg(@RequestBody GroupSendMsgIdDto groupSendMsgIdDto){
        return groupSendJobDetailService.findGroupSendMsg(groupSendMsgIdDto);
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改群发消息", notes = "修改群发消息")
    @ApiOperationSupport(order = 10)
    @PostMapping("/groupSendJobDetail/updateGroupSendMsg")
    public Object updateGroupSendMsg(@RequestBody GroupSendMsgUpdateDto groupSendMsgUpdateDto){
        groupSendJobDetailService.updateGroupSendMsg(groupSendMsgUpdateDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.GroupSendJob, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除群发消息", notes = "删除群发消息")
    @ApiOperationSupport(order = 11)
    @PostMapping("/groupSendJobDetail/deleteGroupSendMsg")
    public Object deleteGroupSendMsg(@RequestBody GroupSendMsgIdDto groupSendMsgIdDto){
        groupSendJobDetailService.deleteGroupSendMsg(groupSendMsgIdDto);
        return true;
    }

}
